<?php
/**
 * Created by PhpStorm.
 * User: xiaoqiang
 * Date: 15-3-21
 * Time: 下午2:00
 */

include_once dirname(dirname(__FILE__)) . "/Library/Function.php";
define("SYS_DIR", dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
define("SYS_LIBRARY", SYS_DIR . "Library" . DIRECTORY_SEPARATOR);
define("SYS_CONFIG", SYS_DIR . "Config" . DIRECTORY_SEPARATOR);
define("SYS_APPLICATION", SYS_DIR . "Application" . DIRECTORY_SEPARATOR);
define("SYS_DATA", SYS_DIR . "Data" . DIRECTORY_SEPARATOR);
define("SYS_LOG", SYS_DATA . "log" . DIRECTORY_SEPARATOR);
define("PREFIX_STATIC", true);
define("DEFAULT_APPLICATION", "Base");
define("DEFAULT_MODULE", "Index");
define("DEFAULT_METHOD", "Index");
spl_autoload_register('autoLoad');
function autoLoad($className)
{
    $className = str_replace("\\", DIRECTORY_SEPARATOR, $className);
    $nameArr = explode(DIRECTORY_SEPARATOR, $className);
    $cls = end($nameArr);
    $prefix = substr($cls, 0, 3);
    if ($prefix == "Lib" && count($nameArr) < 3) {
        $file = SYS_LIBRARY . $cls . ".php";
    } else {
        $end = end($nameArr);
        unset($nameArr[count($nameArr) - 1]);
        if (preg_match('/^ctl(.*)/', $end)) {
            $nameArr[] = 'source';
        }
        if (preg_match('/^mdl(.*)/', $end)) {
            $nameArr[] = 'model';
        }
        $nameArr[] = $end;
        $file = SYS_DIR . implode(DIRECTORY_SEPARATOR, $nameArr) . ".php";
    }

    if (file_exists($file)) {
        include_once($file);
    } else {
        \LibLog::custom("FILE NOT EXISTS :" . $file);
    }
}

